<?php
/**
 * 产生一个指定长度的随机字符串,并返回给用户
 * @param type $len 产生字符串的长度
 * @return string 随机字符串
 */
if ( ! function_exists('get_random_string'))
{
	function get_random_string($len = 6)
	{
		$chars = array(
	        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
	        "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
	        "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
	        "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
	        "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
	        "3", "4", "5", "6", "7", "8", "9"
	        );
	        $charsLen = count($chars) - 1;
	        // 将数组打乱
	        shuffle($chars);
	        $output = "";
	        for ($i = 0; $i < $len; $i++) {
	        	$output .= $chars[mt_rand(0, $charsLen)];
	        }
	        return $output;
	}
}


/**
 * 获取客户端IP地址
 * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
 * @param boolean $adv 是否进行高级模式获取（有可能被伪装）
 * @return mixed
 */
if ( ! function_exists('get_client_ip'))
{
	function get_client_ip($type = 0, $adv = false) {
		$type = $type ? 1 : 0;
		static $ip = NULL;
		if ($ip !== NULL)
		return $ip[$type];
		if ($adv) {
			if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
				$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
				$pos = array_search('unknown', $arr);
				if (false !== $pos)
				unset($arr[$pos]);
				$ip = trim($arr[0]);
			}elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
				$ip = $_SERVER['HTTP_CLIENT_IP'];
			} elseif (isset($_SERVER['REMOTE_ADDR'])) {
				$ip = $_SERVER['REMOTE_ADDR'];
			}
		} elseif (isset($_SERVER['REMOTE_ADDR'])) {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		// IP地址合法验证
		$long = sprintf("%u", ip2long($ip));
		$ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
		return $ip[$type];
	}
}

/**
 * XML编码
 * @param mixed $data 数据
 * @param string $root 根节点名
 * @param string $item 数字索引的子节点名
 * @param string $attr 根节点属性
 * @param string $id   数字索引子节点key转换的属性名
 * @param string $encoding 数据编码
 * @return string
 */
if ( ! function_exists('xml_encode'))
{
	function xml_encode($data, $root='think', $item='item', $attr='', $id='id', $encoding='utf-8') {
		if(is_array($attr)){
			$_attr = array();
			foreach ($attr as $key => $value) {
				$_attr[] = "{$key}=\"{$value}\"";
			}
			$attr = implode(' ', $_attr);
		}
		$attr   = trim($attr);
		$attr   = empty($attr) ? '' : " {$attr}";
		$xml    = "<?xml version=\"1.0\" encoding=\"{$encoding}\"?>";
		$xml   .= "<{$root}{$attr}>";
		$xml   .= data_to_xml($data, $item, $id);
		$xml   .= "</{$root}>";
		return $xml;
	}
}

/**
 * 复制一个目录下面的所有文件到另一个目录
 * @param string $src 源目录
 * @param string $dst 目标目录
 */
if( ! function_exists('recurse_copy')){
	function recurse_copy($src, $dst){
		$dir = opendir($src);
		@mkdir($dst);
		while(false!==($file=readdir($dir))){
			if(($file!='.')&&($file!='..')){
				if(is_dir($src.'/'.$file)){
					recurse_copy($src.'/'.$file, $dst.'/'.$file);
				}else{
					copy($src.'/'.$file,$dst.'/'.$file);
				}
			}
		}
		closedir($dir);
	}
}

/**
 * 删除文件目录以及其子目录及文件
 * @param string $dir 文件目录
 */
if( ! function_exists('del_dir')){
	function del_dir($dir){
		//先删除目录下的文件
		$dh = opendir($dir);
		while($file = readdir($dh)){
			if($file!='.'&&$file!='..'){
				$fulepath = $dir.'/'.$file;
				if(!is_dir($fulepath)){
					unlink($fulepath);
				}else{
					del_dir($fulepath);
				}
			}
		}
		closedir($dh);
		//删除当前文件夹
		if(rmdir($dir)){
			return true;
		}else{
			return false;
		}
	}
}

/**
 * @param $dir
 * @param int $mode
 * @return bool
 */
function dmkdir($dir, $mode = 0777)
{
	if(!is_dir($dir))
	{
		dmkdir(dirname($dir), $mode);
		@mkdir($dir, $mode);
	}
	return true;
}
/**
 * 获取价格格式化信息
 * @param $price
 * @return string
 */
if ( ! function_exists('price_format'))
{
	function price_format($price){
		return sprintf('¥%1.2f',$price);
	}
}
/**
 * 截取字符串
 * @param $str 字符串
 * @param $start 开始位置
 * @param $end   结束位置
 * @param string $charset 字符编码
 * @return mixed
 */
if ( ! function_exists('sub_str'))
{
	function sub_str($str,$start,$end,$charset='utf-8'){
		return mb_substr($str,$start,$end,$charset);
	}
}

if(! function_exists('get_thumb')){
	function get_thumb($orginal_img)
	{
		return filter_img($orginal_img);
	}
}

if(! function_exists('get_diy')){
	function diy($position, $type, $template = '',$echo = 1, $default = '')
	{
		static $CI = null;
		if($CI == null){
			$CI = new CI_Module();
		}
		$CI->load->model('diy.diy_model');
		$ret = $CI->diy_model->get_diy($position, $type, $template);
		$ret = trim($ret);
		if($echo){
			echo $ret ? $ret : $default;
		}else{
			return $ret ? $ret : $default;
		}
	}
}

if(!function_exists('cutstr'))
{
	function cutstr($string, $length, $dot = '...') {
		if(strlen($string) <= $length) {
			return $string;
		}

		$pre = chr(1);
		$end = chr(1);
		$string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), $string);

		$strcut = '';
		if('utf-8') {

			$n = $tn = $noc = 0;
			while($n < strlen($string)) {

				$t = ord($string[$n]);
				if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
					$tn = 1; $n++; $noc++;
				} elseif(194 <= $t && $t <= 223) {
					$tn = 2; $n += 2; $noc += 2;
				} elseif(224 <= $t && $t <= 239) {
					$tn = 3; $n += 3; $noc += 2;
				} elseif(240 <= $t && $t <= 247) {
					$tn = 4; $n += 4; $noc += 2;
				} elseif(248 <= $t && $t <= 251) {
					$tn = 5; $n += 5; $noc += 2;
				} elseif($t == 252 || $t == 253) {
					$tn = 6; $n += 6; $noc += 2;
				} else {
					$n++;
				}

				if($noc >= $length) {
					break;
				}

			}
			if($noc > $length) {
				$n -= $tn;
			}

			$strcut = substr($string, 0, $n);

		} else {
			$_length = $length - 1;
			for($i = 0; $i < $length; $i++) {
				if(ord($string[$i]) <= 127) {
					$strcut .= $string[$i];
				} else if($i < $_length) {
					$strcut .= $string[$i].$string[++$i];
				}
			}
		}

		$strcut = str_replace(array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);

		$pos = strrpos($strcut, chr(1));
		if($pos !== false) {
			$strcut = substr($strcut,0,$pos);
		}
		return $strcut.$dot;
	}
}

if(!function_exists('parse_img'))
{
	function parse_img($string, $allow_remote = 0)
	{
		$pattern = '/<img.*\s+src=([\'"]?)([^\'"]+(jpg|gif|bmp|bnp|png))\\1.+>/iU';
		preg_match_all($pattern, $string,$m);
		$image_list = $m[2];
		foreach ($image_list as $k => $v)
		{
			if(!$allow_remote){
				if(strpos($v, 'http://') !== FALSE || strpos($v, 'HTTP://') !== FALSE)
				{
					unset($image_list[$k]);
				}
			}
		}
		$image_list = array_values($image_list);
		return $image_list;
	}
}

/**
 * 汉字转化为拼音
 * @param $_String
 * @return string
 */
function Pinyin($_String, $_Code='utf8')
{
	$_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha".
"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|".
"cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er".
"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui".
"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang".
"|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang".
"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue".
"|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne".
"|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen".
"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang".
"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|".
"she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|".
"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu".
"|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you".
"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|".
"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
	$_DataValue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990".
"|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725".
"|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263".
"|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003".
"|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697".
"|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211".
"|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922".
"|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468".
"|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664".
"|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407".
"|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959".
"|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652".
"|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369".
"|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128".
"|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914".
"|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645".
"|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149".
"|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087".
"|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658".
"|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340".
"|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888".
"|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585".
"|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847".
"|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055".
"|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780".
"|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274".
"|-10270|-10262|-10260|-10256|-10254";
	$_TDataKey = explode('|', $_DataKey);
	$_TDataValue = explode('|', $_DataValue);
	$_Data = (PHP_VERSION>='5.0') ? array_combine($_TDataKey, $_TDataValue) : _Array_Combine($_TDataKey, $_TDataValue);
	arsort($_Data);
	reset($_Data);
	if($_Code != 'gb2312') $_String = _U2_Utf8_Gb($_String);
	$_Res = '';
	for($i=0; $i<strlen($_String); $i++)
	{
		$_P = ord(substr($_String, $i, 1));
		if($_P>160) { $_Q = ord(substr($_String, ++$i, 1)); $_P = $_P*256 + $_Q - 65536; }
		$_Res .= _Pinyin($_P, $_Data);
	}
	return preg_replace("/[^a-z0-9]*/", '', $_Res);
}
function _Pinyin($_Num, $_Data)
{
	if ($_Num>0 && $_Num<160 ) return chr($_Num);
	elseif($_Num<-20319 || $_Num>-10247) return '';
	else {
		foreach($_Data as $k=>$v){ if($v<=$_Num) break; }
		return $k;
	}
}
function _U2_Utf8_Gb($_C)
{
	$_String = '';
	if($_C < 0x80) $_String .= $_C;
	elseif($_C < 0x800)
	{
		$_String .= chr(0xC0 | $_C>>6);
		$_String .= chr(0x80 | $_C & 0x3F);
	}elseif($_C < 0x10000){
		$_String .= chr(0xE0 | $_C>>12);
		$_String .= chr(0x80 | $_C>>6 & 0x3F);
		$_String .= chr(0x80 | $_C & 0x3F);
	} elseif($_C < 0x200000) {
		$_String .= chr(0xF0 | $_C>>18);
		$_String .= chr(0x80 | $_C>>12 & 0x3F);
		$_String .= chr(0x80 | $_C>>6 & 0x3F);
		$_String .= chr(0x80 | $_C & 0x3F);
	}
	return iconv('UTF-8', 'GB2312', $_String);
}
function _Array_Combine($_Arr1, $_Arr2)
{
	for($i=0; $i<count($_Arr1); $i++) $_Res[$_Arr1[$i]] = $_Arr2[$i];
	return $_Res;
}
if(!function_exists('http_post_data')){
	function http_post_data($url, $data_string) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json; charset=utf-8',
                'Content-Length: ' . strlen($data_string))
		);
		ob_start();
		curl_exec($ch);
		$return_content = ob_get_contents();
		ob_end_clean();

		return @json_decode($return_content, TRUE);
	}
}

function http_post_formdata($url, $field, $file){

	$fields[$field] = '@'.$file;

	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, $url );
	curl_setopt($ch, CURLOPT_POST, 1 );
	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields );

	ob_start();
	curl_exec( $ch );
	$return_content = ob_get_contents();
	ob_end_clean();

	curl_close($ch);
	return @json_decode($return_content, TRUE);
}

/**
 * 对变量进行 JSON 编码
 * @param mixed value 待编码的 value ，除了resource 类型之外，可以为任何数据类型，该函数只能接受 UTF-8 编码的数据
 * @return string 返回 value 值的 JSON 形式
 */
function json_encode_ex($value)
{
	if (version_compare(PHP_VERSION,'5.4.0','<'))
	{
		$str = json_encode($value);
		$str = preg_replace_callback(
            "#\\\u([0-9a-f]{4})#i",
            'iconv_matches',
		$str
		);
		return $str;
	}
	else
	{
		return json_encode($value, JSON_UNESCAPED_UNICODE);
	}
}
function iconv_matches($matchs){
	return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1]));
}

/**
 * 图片路径过滤修改
 */
if(!function_exists('filter_img'))
{
	function filter_img($str){
		$str = str_replace(array('/uploadfile/'),array('/'),$str);
		if(strpos($str,'http')!==FALSE){
			return $str;
		}
		return rtrim(URLPIC,'/').'/'.ltrim($str,'/');
	}
}

function filter_content($str){
	$str = str_replace(array('/uploadfile/','/youhao/'),array('/','/youhaotravel/'),$str);
//    return preg_replace('/(<img.*\s+src=[\'"])([^http])(.+\.(jpg|gif|bmp|bnp|png)\"?.+\, )/i',"\${1}".URLPIC."\${2}\${3}",$str);
    $str = preg_replace('/(<[img|IMG].*?src=[\'|\"])([^http])(.*?(?:[\.jpg|\.gif|\.bmp|\.bnp|\.png]))([\'|\"].*?[\/]?>)/i',"$1".URLPIC."$3$4",$str);
    $str = str_replace('http://www.66diqiu.com/', 'http://photo.66diqiu.com/www/66diqiu/', $str);
    return $str;
}


/**
 * 判断手机端
 */
if(!function_exists('check_wap'))
{
	function check_wap()
	{
		if(stristr(@$_SERVER['HTTP_VIA'],"wap")){// 先检查是否为wap代理，准确度高
			return true;
		}elseif(strpos(strtoupper(@$_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0){// 检查浏览器是否接受 WML.
			return true;
		}elseif(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){//检查USER_AGENT
			return true;
		}else{
			return false;
		}
	}
}

/**
 * 广告位广告信息输出
 * @param $id 广告位置ID
 * @param int $limit 限制数量，如果为一时，则输出完整的广告html
 * @return mixed
 */
if(!function_exists('output_advs'))
{
    function output_advs($id,$limit=1){
        $CI = new CI_Module();
        $CI->load->model('advert.Adresource_model');
        $list = $CI->Adresource_model->get_ads($id,$limit);
        if($limit==1){
            return @$list[0];
        }else{
            return $list;
        }
    }
}

/**
 * 多个广告位广告信息输出
 * @param $data array('8'=>1,'14'=>1,'9'=>1,'10'=>2,'11'=>1,'12'=>1,'13'=>2,'15'=>1) ad_id num
 * @return mixed
 */
if(!function_exists('output_advs_list')) {
    function output_advs_list($data)
    {
        $CI = new CI_Module();
        $CI->load->model('advert.Adresource_model');
        $list = $CI->Adresource_model->get_ads_list($data);
        return $list;
    }
}

/**
 * 将数字转换为汉字，比如1210转换为一千二百一十
 */
if(!function_exists('num2ch'))
{
	function num2ch($num) //整体读取转换
	{
		$num_real = del0($num);//去掉前面的“0”
		$numlen = strlen($num_real);
		if($numlen >= 9)//如果满九位，读取“亿”位
		{
			$y=substr($num_real, -9, 1);
			$wsbq = substr($num_real, -8, 4);
			$gsbq = substr($num_real, -4);
			$a = num_r(del0($gsbq));
			$b = num_r(del0($wsbq))."万";
			$c = num_r(del0($y))."亿";
		}elseif($numlen <= 8 && $numlen >= 5) //如果大于等于“万”
		{
			$wsbq = substr($num_real, 0, $numlen-4);
			$gsbq = substr($num_real, -4);
			$a = num_r(del0($gsbq));
			$b = num_r(del0($wsbq))."万";
			$c="";
		}elseif($numlen <= 4) //如果小于等于“千”
		{
			$gsbq = substr( $num_real, -$numlen);
			$a = num_r(del0($gsbq));
			$b="";
			$c="";
		}
		$ch_num = $c.$b.$a;
		return $ch_num;
	}
}

/**
 * 去掉数字段前面的0
 */
if(!function_exists('del0'))
{
	function del0($num)
	{
		return "".intval($num);
	}
}

/**
 * 单个数字变汉字
 */
if(!function_exists('n2c'))
{
	function n2c($x)
	{
		$arr_n = array("零","一","二","三","四","五","六","七","八","九","十");
		return $arr_n[$x];
	}
}

/**
 * 时间戳转化
 */
if(!function_exists('transform_week')) {
    function transform_week($time)
    {
        $weekarray = array("日","一","二","三","四","五","六");
        return $weekarray[date('w',$time)];
    }
}
/**
 * 时间戳转化
 */
if(!function_exists('transform_time')) {

    function transform_time($time)
    {
        $rtime = date("m-d H:i", $time);
        $htime = date("H:i", $time);
        $time = time() - $time;
        if ($time < 60) {
            $str = '刚刚';
        } elseif ($time < 60 * 60) {
            $min = floor($time / 60);
            $str = $min . '分钟前';
        } elseif ($time < 60 * 60 * 24) {
            $h = floor($time / (60 * 60));
            $str = $h . '小时前 ' . $htime;
        } elseif ($time < 60 * 60 * 24 * 3) {
            $d = floor($time / (60 * 60 * 24));
            if ($d == 1)
                $str = '昨天 ' . $rtime;
            else
                $str = '前天 ' . $rtime;
        }
        else {
            $str = $rtime;
        }
        return $str;
    }
}

/**
 * 读取数值（4位）
 */
if(!function_exists('num_r'))
{
	function num_r($abcd)
	{
		$arr= array();
		$str = ""; //读取后的汉字数值
		$flag = 0; //该位是否为零
		$flag_end = 1; //是否以“零”结尾
		$size_r = strlen($abcd);
		for($i=0; $i<$size_r; $i++)
		{
			$arr[$i] = $abcd{$i};
		}
		$arrlen = count($arr);
		for($j=0; $j<$arrlen; $j++)
		{
			$ch = n2c($arr[$arrlen-1-$j]); //从后向前转汉字
			if($ch == "零" && $flag == 0){ //如果是第一个零
				$flag = 1; //该位为零
				$str = $ch.$str; //加入汉字数值字符串
				continue;
			}elseif($ch == "零"){ //如果不是第一个零了
				continue;
			}
			$flag = 0; //该位不是零
			switch($j) {
				case 0: $str = $ch; $flag_end = 0; break; //第一位（末尾），没有以“零”结尾
				case 1: $str = $ch."十".$str; break; //第二位
				case 2: $str = $ch."百".$str; break; //第三位
				case 3: $str = $ch."千".$str; break; //第四位
			}
		}
		if($flag_end == 1) //如果以“零”结尾
		{
			mb_internal_encoding("UTF-8");
			$str = mb_substr($str, 0, mb_strlen($str)-1); //把“零”去掉
		}
		return $str;
	}
}
/**
 * 删除数组中多余的空格
 */
if(!function_exists('array_filter_null'))
{
function array_filter_null($param){
	if($param==''){
	    return false;
        }else{
            return true;
        }
	}
}

/**
 * 航空公司简称转换
 */
if(!function_exists('airline_word_to_name'))
{
    function airline_word_to_name($param){
        $param = substr($param,0,2);
        $data = array('3U'=>'四川航空','BK'=>'奥凯航空','8L'=>'祥鹏航空',
                      'CA'=>'中国航空','CN'=>'大新华航空','CZ'=>'南方航空',
                      'FM'=>'上海航空','HO'=>'吉祥航空','HU'=>'海南航空',
                      'JD'=>'金鹿航空','JR'=>'幸福航空','MF'=>'厦门航空',
                      'MU'=>'东方航空','PN'=>'西部航空','SC'=>'山东航空',
                      'ZH'=>'深圳航空');
        return $data[$param];
    }
}


/**
 * 舱位转换
 */
if(!function_exists('cabin_to_name'))
{
    function cabin_to_name($param){

        $gw = array('C','D');
        $td = array('A','F');
        if(in_array($param,$gw)) return '公务舱' ;
        if(in_array($param,$td)) return '头等舱' ;
        return '经济舱' ;
    }
}



/**
 * 获取推荐分类的链接地址
 */
if(!function_exists('recommend_link')){
    function recommend_link($name){
        return site_url($name);
    }
}




/**
 * curl/socket 请求函数
 *
 */
if(!function_exists('_dfsockopen')) {

    function _dfsockopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE, $position = 0, $files = array())
    {
        $return = '';
        $matches = parse_url($url);
        $scheme = $matches['scheme'];
        $host = $matches['host'];
        @$path = $matches['path'] ? $matches['path'] . ($matches['query'] ? '?' . $matches['query'] : '') : '/';
        $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'http' ? '80' : '');
        $boundary = $encodetype == 'URLENCODE' ? '' : random(40);

        if ($post) {
            if (!is_array($post)) {
                parse_str($post, $post);
            }
            _format_postkey($post, $postnew);
            $post = $postnew;
        }

        if ($post) {
            if ($encodetype == 'URLENCODE') {
                $data = http_build_query($post);
            } else {
                $data = '';
                foreach ($post as $k => $v) {
                    $data .= "--$boundary\r\n";
                    $data .= 'Content-Disposition: form-data; name="' . $k . '"' . (isset($files[$k]) ? '; filename="' . basename($files[$k]) . '"; Content-Type: application/octet-stream' : '') . "\r\n\r\n";
                    $data .= $v . "\r\n";
                }
                foreach ($files as $k => $file) {
                    if (!isset($post[$k]) && file_exists($file)) {
                        if ($fp = @fopen($file, 'r')) {
                            $v = fread($fp, filesize($file));
                            fclose($fp);
                            $data .= "--$boundary\r\n";
                            $data .= 'Content-Disposition: form-data; name="' . $k . '"; filename="' . basename($file) . '"; Content-Type: application/octet-stream' . "\r\n\r\n";
                            $data .= $v . "\r\n";
                        }
                    }
                }
                $data .= "--$boundary\r\n";
            }
            $out = "POST $path HTTP/1.0\r\n";
            $header = "Accept: */*\r\n";
            $header .= "Accept-Language: zh-cn\r\n";
            $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data; boundary=$boundary\r\n";
            $header .= 'Content-Length: ' . strlen($data) . "\r\n";
            @$header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
            $header .= "Host: $host:$port\r\n";
            $header .= "Connection: Close\r\n";
            $header .= "Cache-Control: no-cache\r\n";
            $header .= "Cookie: $cookie\r\n\r\n";
            $out .= $header;
            $out .= $data;
        } else {
            $out = "GET $path HTTP/1.0\r\n";
            $header = "Accept: */*\r\n";
            $header .= "Accept-Language: zh-cn\r\n";
            $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
            $header .= "Host: $host:$port\r\n";
            $header .= "Connection: Close\r\n";
            $header .= "Cookie: $cookie\r\n\r\n";
            $out .= $header;
        }

        $fpflag = 0;
        if (!$fp = @fsocketopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout)) {
            $context = array(
                'http' => array(
                    'method' => $post ? 'POST' : 'GET',
                    'header' => $header,
                    'content' => $post,
                    'timeout' => $timeout,
                ),
            );
            $context = stream_context_create($context);
            $fp = @fopen($scheme . '://' . ($ip ? $ip : $host) . ':' . $port . $path, 'b', false, $context);
            $fpflag = 1;
        }

        if (!$fp) {
            return '';
        } else {
            $headers = $oldchar = '';
            stream_set_blocking($fp, $block);
            stream_set_timeout($fp, $timeout);
            @fwrite($fp, $out);
            $status = stream_get_meta_data($fp);
            if (!$status['timed_out']) {
                while (!feof($fp) && !$fpflag) {
                    $header = @fgets($fp);
                    $headers .= $header;
                    if ($header && ($header == "\r\n" || $header == "\n")) {
                        break;
                    }
                }
                $GLOBALS['filesockheader'] = $headers;

                if ($position) {
                    for ($i = 0; $i < $position; $i++) {
                        $char = fgetc($fp);
                        if ($char == "\n" && $oldchar != "\r") {
                            $i++;
                        }
                        $oldchar = $char;
                    }
                }

                if ($limit) {
                    $return = stream_get_contents($fp, $limit);
                } else {
                    $return = stream_get_contents($fp);
                }
            }
            @fclose($fp);
            return $return;
        }
    }

}

/**
 * socket函数
 *
 */

if(!function_exists('fsocketopen')) {
    function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) {
        $fp = '';
        if(function_exists('fsockopen')) {
            $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
        } elseif(function_exists('pfsockopen')) {
            $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
        } elseif(function_exists('stream_socket_client')) {
            $fp = @stream_socket_client($hostname.':'.$port, $errno, $errstr, $timeout);
        }

        if(!$fp)
        {
            if(TEST_SMS)
            {
                print_r(array('host'=>$hostname,'port'=>$port,'errno'=>$errno));
                exit();
            }
        }
        return $fp;
    }

}

/**
 * curl函数数组处理
 *
 */
if(!function_exists('_format_postkey')) {
    function _format_postkey($post, &$result, $key = '')
    {
        foreach ($post as $k => $v) {
            $_k = $key ? $key . '[' . $k . ']' : $k;
            if (is_array($v)) {
                _format_postkey($v, $result, $_k);
            } else {
                $result[$_k] = $v;
            }
        }
    }
}



if(!function_exists('debug_output')) {
    function debug_output($str)
    {
        echo '<pre>';
        print_r($str);
        echo'</pre>';
    }
}
if(!function_exists('comment_count')) {
    /**
     * 点评统计
     */
    function comment_count()
    {
        $CI = new CI_Module();
        $table = $CI->db->dbprefix("comment");
        $sql = "SELECT COUNT(*) as num,sum(star) as stars FROM " . $table;
        $row = $CI->db->query($sql)->row_array();
        $row['comment_degree'] = ($row['stars'] / ($row['num'] * 5)) * 100;
        return $row;
    }
}

if(!function_exists('tourist_count')) {
    /**
     * 游客人数统计
     */
    function tourist_count()
    {
        $CI = new CI_Module();
        $table = $CI->db->dbprefix("order_tourist");
        $sql = "SELECT COUNT(*) as num FROM " . $table;
        $row = $CI->db->query($sql)->row_array();
        return $row['num'];
    }
}

/**
 * 根据时间获取现在的时间段
 */
if(!function_exists('time_delimit')){
	function time_delimit(){
        $hour = date('G',now());
		if($hour>4&&$hour<=10){
			return 1;
		}elseif($hour>10&&$hour<=14){
			return 2;
		}elseif($hour>14&&$hour<=16){
			return 3;
		}elseif($hour>16&&$hour<=21){
			return 4;
		}else{
			return 5;
		}
	}
}


if(!function_exists('submitcheck')){
    function submitcheck($param = '') {
        if($param && !$_REQUEST[$param]){
            return FALSE;
        }
        if($_REQUEST[$param]){
            $ret = $_REQUEST[$param];
        }else{
            $ret = $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SERVER['HTTP_X_FLASH_VERSION']);
        }
        return $ret;
    }
}

/**
 * 获取当前页面完整URL地址
 */
if(!function_exists('get_url')){
    function get_url($related = 0) {
        $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
        $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
        $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
        $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);
        return $related ? $relate_url : $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
    }
}


if(!function_exists('thumb')){
    function thumb($image) {
//        return str_replace('.','_thumb.',$image);
        return $image;
    }
}

function __get_signature($appid,$appsecret, $noncestr, $acurl, $timestamp)
{
    if(empty($appid) || empty($appsecret)){
        return '';
    }

    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
    $ret = file_get_contents($url);
    $ret = json_decode($ret, TRUE);
    $access_token = $ret['access_token'];


    $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=$access_token&type=jsapi";
    $ret = file_get_contents($url);

    $ret = json_decode($ret, TRUE);
    $string1 = "jsapi_ticket=$ret[ticket]&noncestr=$noncestr&timestamp=$timestamp&url=$acurl";

    $signature = sha1( $string1 );
    return $signature;
}

function __get_sharehtml($title, $description, $imgurl = ''){

	$CI = new CI_Module();
	$CI->load->model('weixin.weixin_model');

	if($_GET['eid']){
		$user_id = intval($_GET['eid']) ;
	}else if($_COOKIE['from_card']){
		$user_id = intval($_COOKIE['from_card']) ;
	}

	$setting = $CI->weixin_model->db_get_setting();

	$appid = $setting['appid'];
	$appsecret = $setting['appsecret'];
	$geturl = get_url();
	$noncestr = uniqid('wx');
	$timestamp = time();
	$signature = __get_signature($appid, $appsecret, $noncestr, $geturl, $timestamp);

	$debug = DEBUG ? 'true' : 'false';
	$incrurl = site_url('mobile/member/card/?eid='.$user_id.'&incr=1');
	$sharehtml = <<<HTML
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
var title='$title', desc='$description', link='$geturl',imgUrl='$imgurl';
wx.config({
    debug:$debug,
    appId: '$appid',
    timestamp: $timestamp,
    nonceStr: '$noncestr',
    signature: '$signature',
    jsApiList: [
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo'
    ]
});
function todoaftershare() {
  $.get('$incrurl', function(){
  });
}
wx.ready(function () {
    wx.onMenuShareAppMessage({title: title,desc: desc,link: link,imgUrl: imgUrl,success:function(){    todoaftershare();}});
    wx.onMenuShareTimeline({title: title,link: link,imgUrl: imgUrl,success:function(){    todoaftershare();}  });
    wx.onMenuShareQQ({title: title,desc: desc,link: link,imgUrl: imgUrl,success:function(){    todoaftershare();}   });
    wx.onMenuShareWeibo({title: title,desc: desc,link: link,imgUrl: imgUrl,success:function(){    todoaftershare();}   });
});
</script>
HTML;
	return $sharehtml;
}


/**
 * 添加微信响应消息
 * @param $array
 * @return true/false
 */
if(!function_exists('_add_weixin_response_text')){
    function _add_weixin_response_text($array)
    {
        $CI = new CI_Module();
        $CI->load->model('weixin.Response_model');
        return $CI->Response_model->_add_response_text($array);
    }
}

/**
 * 处理特殊符号连接的字符串
 * @param $string
 * @return true/false
 */

if(!function_exists('_process_string_to_array')) {
    function _process_string_to_array($string)
    {
        $string = str_replace(array('，', ' ', '。', '.', '　'), ',', trim($string));
        return   array_filter(explode(',', $string));
    }
}

/**
 * 处理微信响应消息
 * @param $keyword
 * @return true/false
 */

if(!function_exists('_process_weixin_response_text')){
    function _process_weixin_response_text($keyword = '')
    {
        $CI = new CI_Module();
        $CI->load->model('weixin.Response_model');
        $result = $CI->Response_model->get_row("sid = {$GLOBALS['sid']} AND keywords = '".$keyword."'");
        if (!$result) return NULL;
        switch ($result['type']){

            case "1" :  // 自定义网址类型

                $serialize = unserialize($result['content']);
                $data = array(
                    'title' => $serialize['title'],
                    'description' => $serialize['description'],
                    'picurl' => URLPIC.$serialize['pic'],
                    'url' => $serialize['url']
                );

                return  array('items'=>array($data));
            break;

            case "2" : // 线路类型

                $CI->load->model('line.Line_model');
                $line_numbers = _process_string_to_array($result['content']);
                $line_numbers = array_slice($line_numbers,0,10);
                $result = $CI->Line_model->get_line_list($line_numbers);
                if($result)
                {
                    foreach($result as $key=>$val){

                        $data[$key]['title'] =  $val['line_name'];
                        $data[$key]['description'] =  $val['line_trait'];
                        $data[$key]['picurl'] = rtrim(URLPIC, '/').'/'.ltrim($val['line_thumb'] , '/');
                        $data[$key]['url'] = site_url('/mobile/line/profile/?id='.$val['line_id']);
                    }
                    $data = array_values($data);
                    return  array('items'=>$data);
                }

            break;
        }


    }
}


//========================微店绑定功能,暂停开发,20150925=============================================

/**
 * 判断是否绑定微店
 * @param $open_id 微信open_id
 * @return true/false
 */

if(!function_exists('_is_bind_weixin_shop')) {
    function _is_bind_weixin_shop($openid='')
    {
        if(empty($openid)) return FALSE;
        $CI = new CI_Module();
        $CI->load->model('weixin.Shop_model');
        $shop_table = $CI->db->dbprefix('user_shop_info');
        $result = $CI->Shop_model->get_row("$shop_table.openid = '".$openid."' AND $shop_table.sid = ".$GLOBALS['sid']);
        return empty($result) ? FALSE : TRUE;
    }
}

/**
 * 绑定微店
 * @param $mobile 手机号
 * @param $open_id 微信open_id
 * @return true/false
 */

if (!function_exists('_bind_weixin_shop')) {
    function _bind_weixin_shop($mobile = '', $openid = '')
    {
        if (empty($mobile) || empty($openid))  return FALSE;
        $CI = new CI_Module();
        $CI->load->model('weixin.Shop_model');
        $user_table = $CI->db->dbprefix('user');
        $shop_table = $CI->db->dbprefix('user_shop_info');
        $result = $CI->Shop_model->get_row("$user_table.mobile = '" . $mobile . "' AND $shop_table.sid = ".$GLOBALS['sid']);
        if(empty($result)) return FALSE;
       // if(_is_bind_weixin_shop($openid)) return $CI->db->last_query();
        $data = array('openid' => $openid);
        $where = array('pid' => $result['user_id'], 'sid' => $GLOBALS['sid']);
        return $CI->Shop_model->_edit_shop_info($data, $where);
    }
}

/**
 * 通过openid查看微店
 * @param $open_id 微信open_id
 * @return true/false
 */

if (!function_exists('_get_shop_by_openid')) {
    function _get_shop_by_openid($openid = '')
    {
        if (empty($openid)) return FALSE;
        $return = array();
        $CI = new CI_Module();
        $CI->load->model('weixin.Shop_model');
        $shop_table = $CI->db->dbprefix('user_shop_info');
        $result = $CI->Shop_model->get_row("$shop_table.opend = '" . $openid . "' AND $shop_table.sid = ".$GLOBALS['sid']);
        if (!$result) return $return;
        $return = array(
            'items' =>
                array(
                    array(
                        'title' => $result['shopname'],
                        'description' => '',
                        'picurl' => URLPIC.$result['avatar'],
                        'url' => site_url('mobile/member/card/?eid='.$result['id'])
                    )
                )
        );
        return $return ;
    }
}

/**
 * 解绑微店
 * @param $open_id 微信open_id
 * @return true/false
 */

if (!function_exists('_unbind_weixin_shop')) {
    function _unbind_weixin_shop($openid = '')
    {
        if (empty($openid)) return FALSE;
        $CI = new CI_Module();
        $CI->load->model('weixin.Shop_model');
        $data = array('openid' => '0');
        $where = array('openid' => $openid, 'sid' => $GLOBALS['sid']);
        $CI->Shop_model->_edit_shop_info($data, $where);
        return $CI->db->affected_rows();
    }
}
if (!function_exists('get_product_sort_name')) {
	function get_product_sort_name($procut_sort)
	{
		//1跟团2自助3公司4当地5邮轮6亲子7夕阳红8蜜月
		$names = array(
			1 => '跟团游',
			2 => '自助游',
			3 => '公司游',
			4 => '当地游',
			5 => '邮轮游',
			6 => '亲子游',
			7 => '夕阳红游',
			8 => '蜜月游',
		);
		return $names[$procut_sort];
	}
}
//===============================================================================================

if (!function_exists('get_countdown')) {
	function get_countdown($unix_time = '')
	{
		if(empty($unix_time)) return false;
		if($unix_time < time()) return array("day" => 0,"hour" => 0,"min" => 0,"sec" => 0);;
		$timediff = $unix_time - time();
		$days = intval($timediff/86400);
		$remain = $timediff%86400;
		$hours = intval($remain/3600);
		$remain = $remain%3600;
		$mins = intval($remain/60);
		$secs = $remain%60;
		$res = array("day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs);
		return $res;
 	}
}

if(!function_exists('jinri_error')){
	function jinri_error($code){

		$ar = array(
				000003 => "中航信返回订位失败",
				100000 => "请求xml字符串存在SQL注入",
				100001 => "请求的XML格式有误",
				100002 => "请求的XML字符串中经销商账户存在非法字符",
				100003 => "请求的XML字符串中经销商账户未填写",
				100004 => "请求的XML字符串的出发城市三字码不合法",
				100006 => "请求的XML字符串的到达城市三字码不合法",
				100007 => "航班号为空或不合法",
				100008 => "请求的XML字符串的出发日期格式不合法（2012-05-30）",
				100009 => "请求的XML字符串的出发日期格式未填写",
				100010 => "请求的XML字符串的舱位不合法",
				100011 => "请求的XML字符串的舱位未填写",
				100012 => "经销商账户不存在",
				100013 => "经销商航班查询流量不足",
				100014 => "经销商账户IP未绑定",
				100015 => "更新经销商流量失败",
				100016 => "加载黑屏数据失败",
				100017 => "政策匹配异常",
				100018 => "请求的XML字符串的舱位为空",
				100019 => "请求的XML字符串中经销商账户未空",
				100020 => "请求的XML字符串的出发城市三字码为空",
				100021 => "请求的XML字符串的到达城市三字码为空",
				100022 => "请求的XML字符串中SystemId在系统中不存在",
				100023 => "请求的XML字符串中isshowspecial字段必须为T或F",
				100024 => "没有可用的航班数据",
				100025 => "构建特价舱位价格结果异常",
				100026 => "请求的XML字符串中每页显示行数不合法",
				100027 => "请求的XML字符串中总页数不合法",
				100028 => "请求的XML字符串中每页显示行数为空或null",
				100029 => "请求的XML字符串中总页数为空或null",
				100030 => "请求的XML字符串中的航空公司二字码为空或null",
				100031 => "解析XML异常",
				100032 => "构建航班查询XML结果集异常",
				100033 => "航班查询无可用舱位或无可用政策",
				210001 => "获取政策异常",
				210002 => "获取保底政策异常",
				210003 => "获取政策可访问次数出错",
				210004 => "更新查询政策兑换剩余次数出错",
				210005 => "更新政策访问次数出错",
				210006 => "缺少rate_count配置",
				210007 => "获取政策数据格式化xml字符串异常",
				210008 => "根据供票商，获取采购应支付的手续费转换异常",
				210009 => "获取政策数据DataTable转换成xmlDoc格式化异常",
				210010 => "获取政策异常",
				210011 => "获取政策信息异常",
				210012 => "获取政策下载包信息异常",
				210013 => "获取下载包政策异常",
				210014 => "航空公获取政策下载包数据库异",
				210015 => "获取被删除的政策ID集合信息异常",
				210016 => "获取其他特殊政策列表[全国对全国政策]信息异常",
				210017 => "获取被删除的政策ID异常",
				210018 => "获取其他特殊政策异常",
				210019 => "获取其他特殊政策数据异常",
				210020 => "根据政策id获取供票商的officeNum异常",
				210021 => "根据Pnr获取政策信息异常",
				210022 => "解析pnr异常",
				210023 => "无法解析PNR信息",
				210024 => "获取基础包政策异常",
				210025 => "获取更新包政策异常",
				210026 => "获取航班可访问次数出错",
				210027 => "更新查询航班兑换剩余次数出错",
				210028 => "缺少post_count配置",
				210029 => "获取航班可访问次数出错",
				220001 => "请求参数非法",
				220002 => "请求参数节点异常",
				220003 => "用户名存在非法字符",
				220004 => "用户名不能为空或NULL",
				220005 => "出发城市存在非法字符",
				220006 => "出发城市三字码不存在",
				220007 => "出发城市不能为空或NULL",
				220008 => "到达城市存在非法字符",
				220009 => "到达城市三字码不存在",
				220010 => "到达城市不能为空或NULL",
				220011 => "航班日期存在非法字符",
				220012 => "航班日期格式不正确",
				220013 => "航班日期不能为空或NULL",
				220014 => "航空公司存在非法字符",
				220015 => "航程类型必须为数字",
				220016 => "航程类型存在非法字符或者航程类型参数值不在0,1,2",
				220017 => "记录条数必须为数字",
				220018 => "记录条数存在非法字符或者记录条数小于1",
				220019 => "记录条数不能为空或NULL",
				220020 => "舱位存在非法字符",
				220021 => "舱位不存在",
				220022 => "政策类型必须为数字或者政策类型参数值不在0,1,2",
				220023 => "乘客类型必须为数字或者乘客类型参数值不在0,1,2",
				220024 => "请求参数异常",
				220025 => "未开通权限",
				220026 => "IP未绑定，请联系今日",
				220027 => "获取用户信息异常",
				220028 => "访问超量了，请联系今日充值",
				220029 => "没有任何请求数据",
				220030 => "不存在该用户",
				220031 => "下载包类型必须为数字",
				220032 => "请求的下载包类型参数值不在0,1",
				220033 => "下载包类型存在非法字符",
				220034 => "uptime日期存在非法字符",
				220035 => "uptime日期格式不正确",
				220036 => "uptime日期不能为空或NULL",
				220037 => "tm存在非法字符",
				220038 => "tm格式不正确",
				220039 => "TM至必须在0-479范围内",
				220040 => "tm不能为空或NULL",
				220041 => "tm值计算出的时间是否大于当前时间",
				220042 => "时间点参数格式不正确",
				220043 => "政策类型参数格式不正确",
				220044 => "PNR存在非法字符",
				220045 => "PNR格式不正确",
				220046 => "PNR不能为空或NULL",
				220047 => "PNRInfo存在非法字符",
				220048 => "乘客类型存在非法字符",
				220049 => "乘客类型存在非法字符",
				220050 => "PNRInfo格式错误或者为空",
				220051 => "zip压缩文件异常",
				220052 => "生成xml文件异常",
				220053 => "政策更新包传入时间异常",
				220054 => "未找到request请求节点",
				220055 => "该用户不存在",
				220056 => "航班号存在非法字符",
				220057 => "政策id不能为空或NULL或0",
				220058 => "政策id不合法",
				220059 => "没有查询到符合条件的数据",
				220060 => "系统服务商必须为数字",
				220061 => "系统服务商存在非法字符",
				220062 => "系统商未获得授权",
				220063 => "系统商授权记录未通过审核",
				220064 => "基础政策包只能在凌晨1点至8点获取",
				220065 => "当日起飞的航班客票当日一经出票不得当日作废",
				220066 => "获取退改签说明异常",
				220067 => "获取退废规定时，舱位列表解析异常",
				220068 => "获取改签规定时，舱位列表解析异常",
				220069 => "获取退改签规定时，序列化异常",
				220070 => "获取验证废票信息失败",
				220071 => "记录条数不能大于10",
				220072 => "政策类型必须为数字或者政策类型参数值不在1,2",
				220073 => "政策更新包时间只能为当天时间",
				220074 => "政策更新包时间不能大于当前时间",
				220075 => "政策更新包时间格式是日期+时间",
				220076 => "无可用政策",
				220077 => "获取剩余库存异常",
				220078 => "政策类型不能为空",
				220079 => "舱位不能为空",
				220080 => "航班号不能为空",
				220081 => "密码不能为空或NULL",
				220082 => "请求ID为空或NULL",
				220083 => "密码验证错误",
				220084 => "用户密码有误或用户IP未绑定",
				220086 => "退票航段与订单中的航段不一致",
				220087 => "退票信息不能为空或为NULL",
				220089 => "退票航段未填写",
				220090 => "退款类型未填写",
				220091 => "未获取到此用户IP信息",
				220092 => "基建费不能为空或为NULL",
				220093 => "燃油费不能为空或为NULL",
				220094 => "票面价不能为空或为NULL",
				220095 => "结算价不能为空或为NULL",
				220096 => "行程类型不能为空或为NULL",
				220097 => "航段信息不能为空或为NULL",
				220098 => "乘机人信息不能为空或为NULL",
				220099 => "行程类型不合法,只能为1或2",
				220100 => "证件类型不能为空或为NULL",
				220101 => "出生日期不能为空或为NULL",
				220102 => "到达日期不能为空或为NULL",
				220103 => "航段号不能为空或为NULL",
				300001 => "无效的采购账户",
				300002 => "IP地址未绑定",
				300003 => "经销商账户不具备查询访问流量",
				300004 => "创建PNR失败",
				300005 => "政策ID和供应商ID必须有一项有值",
				300006 => "没有匹配到政策",
				300007 => "获取officeNum有误",
				300008 => "初始化Pnr信息有误",
				300009 => "获取出发城市和到达城市之间的公里数失败",
				300010 => "统计异常",
				300011 => "采购返点大于政策返点",
				300012 => "创建PNR编码有误",
				300013 => "存入订单记录失败",
				300014 => "存入订单日志失败",
				300015 => "存入订单扩展失败",
				300016 => "存入后返金额失败",
				300017 => "存入块钱支付失败",
				300018 => "采购商用户不存在",
				300019 => "PnrInfo数据有误",
				300020 => "采购商账户未填写",
				300021 => "采购商账户为空",
				300022 => "政策Id和供应商ID为空或不存在",
				300023 => "乘客姓名为空",
				300024 => "乘客姓名不存在",
				300025 => "乘客证件不存在",
				300026 => "乘客证件号为空",
				300027 => "舱位为空",
				300028 => "舱位为空",
				300029 => "航班号不存在",
				300030 => "航班号为空",
				300031 => "出发日期为不存在",
				300032 => "出发日期为空",
				300033 => "出发日期格式不合法",
				300034 => "出发城市不存在",
				300035 => "出发城市为空",
				300036 => "出发城市三字码不合法",
				300037 => "到达城市不存在",
				300038 => "到达城市为空",
				300039 => "到达城市三字码不合法",
				300040 => "返点不存在",
				300041 => "采购商的返点为空",
				300042 => "允许换编码创单值不合法，必须为0或1",
				300043 => "政策类型值不合法，必须为0或1或2",
				300044 => "自动支付值不合法，必须为F或T",
				300045 => "乘客类型的值不合法，必须为A或C",
				300046 => "解析xml异常",
				300047 => "构建xml响应数据异常",
				300048 => "乘客人数与乘客姓名，乘客证件不匹配",
				300049 => "pnr编码为填写",
				300050 => "pnr编码为空",
				300051 => "Pnrinfo未填写",
				300052 => "Pnrinfo内容为空",
				300053 => "pnrInfo数据不合法",
				300054 => "航线类型不合法，其值必须为O,F,T",
				300055 => "舱位类型不合法，其中必须为T，P，C",
				300056 => "初始化Pnr信息有误",
				300057 => "系统查询机票价格出现异常",
				300058 => "未获取到特价舱位价格",
				300059 => "获取出发城市和到达城市之间的公里数失败",
				300060 => "机建燃油费不符",
				300061 => "该经销商用户不允许重创建订单",
				300062 => "订单未支付",
				300063 => "订单不存在",
				300064 => "供应商正在处理订单",
				300065 => "供应商ID不存在分润模式",
				300066 => "当前订单已经出票完成，不允许取消订单",
				300067 => "当前订单状态,不允许取消订单",
				300068 => "抱歉！不能完成此操作，该编码供票商已出票！",
				300069 => "订单取消成功，存入订单日志失败",
				300070 => "订单状态不能取消订单",
				300071 => "订单编号未填写",
				300072 => "订单编号为空",
				300073 => "pnr编码未填写",
				300074 => "pnr编码为空",
				300075 => "支付类型未填写",
				300076 => "支付类型为空",
				300077 => "支付类型必须为ZFB，KQ，CFT中的一种",
				300078 => "退/费票标识不存在",
				300079 => "退/费票标识为空",
				300080 => "乘客姓名未填写",
				300081 => "乘客姓名为空",
				300082 => "退/费票人数未填写",
				300083 => "退/费票人数为空",
				300084 => "退/费票人数必须为数字",
				300085 => "退/费票的票号未填写",
				300086 => "退/费票的票号为空",
				300087 => "票号与退费票标识不相等",
				300088 => "票号与乘客名称不相等",
				300089 => "退/费票标识有误",
				300090 => "退/费票人数与退/费票姓名不相等",
				300091 => "退/废票标识未填写",
				300092 => "退/费票为空",
				300093 => "乘客姓名，票号不匹配",
				300094 => "退/废票标识与退/废票类型不匹配",
				300095 => "该用户已经退/费票处理",
				300096 => "乘客姓名未填写",
				300097 => "乘客姓名为空",
				300098 => "出发日期未填写",
				300099 => "出发日期为空",
				300100 => "出发日期格式不正确",
				300101 => "出发时间未填写",
				300102 => "出发时间为空",
				300103 => "出发时间格式不正确",
				300104 => "航班号未填写",
				300105 => "航班号为空",
				300106 => "舱位未填写",
				300107 => "舱位为空",
				300108 => "采购商账户无效",
				300109 => "存入支付跳转失败",
				300110 => "存入升舱信息失败",
				300111 => "用户名未填写",
				300112 => "用户名为空",
				300113 => "成人Pnr编码未填写",
				300114 => "成人Pnr编码为空",
				300115 => "成人Pnr编码格式不正确",
				300116 => "舱位编码未填写",
				300117 => "舱位编码为空",
				300118 => "乘客人数未填写",
				300119 => "乘客人数为空",
				300120 => "乘客人数必须为数字",
				300121 => "乘客姓名未填写",
				300122 => "乘客姓名为空",
				300123 => "乘客证件号未填写",
				300124 => "乘客证件号为空",
				300125 => "乘客证件号与乘客人数不相等",
				300126 => "乘客姓名与乘客人数不相等",
				300127 => "不存在该用户",
				300128 => "获取行程单标识不存在",
				300129 => "行程单标识为空",
				300130 => "行程单标识有误",
				300131 => "获取行程单方式未填写",
				300132 => "获取行程单方式为空",
				300133 => "获取行程单方式有误",
				300134 => "联系人为填写",
				300135 => "联系人为空",
				300136 => "电话号码未填写",
				300137 => "电话号码为空",
				300138 => "地址未填写",
				300139 => "地址为空",
				300140 => "省份为填写",
				300141 => "省份为空",
				300142 => "城市未填写",
				300143 => "城市为空",
				300144 => "订单编号不存在",
				300145 => "订单状态不能申请程单",
				300146 => "乘客姓名不存在",
				300147 => "乘客已经申请行程单",
				300148 => "采购商账户不存在",
				300149 => "邮政编码为6位",
				300150 => "行程单编号未填写",
				300151 => "行程单编号为空",
				300152 => "票号为空",
				300153 => "票号未填写",
				300154 => "订单时间未填写",
				300155 => "订单时间为空",
				300156 => "订单时间格式有误",
				300157 => "票号不存在",
				300158 => "请求参数code未填写",
				300159 => "请求参数code为空",
				300160 => "请求类型(type)未填写",
				300161 => "请求类型(type)为空",
				300162 => "请求类型的值有误，必须在(1,2,3,4)",
				300163 => "更新访问次数失败",
				300164 => "供应商ID为空",
				300165 => "供应商名称不存在",
				300166 => "政策ID不存在",
				300167 => "订单号不存在",
				300168 => "该订单编号不存在officeNum",
				300169 => "该订单没有升舱记录",
				300170 => "系统出现故障，暂时无法进行导入创建订单，出现此情况，请及时联系我们",
				300171 => "此记录编号不存在，请确认再导入PNR记录编号",
				300172 => "此记录编号无效，状态为已取消",
				300173 => "此记录编号含有儿童，请使用下面儿童PNR导入创建订单",
				300174 => "此记录编号暂时无法导入创建订单，请联系我们",
				300175 => "此记录编号无运价信息，请检查PNR记录编码",
				300176 => "此记录编号未添加证件号码，加入后请重新导入PNR记录编号",
				300177 => "此记录编号为共享航班，如果订购共享航班请联系客服",
				300178 => "此记录编号位置被“NO”掉了，请检查您的PNR记录编号",
				300179 => "此记录编号为“HL”状态不是有效记录编号，请检查您的PNR记录编号",
				300180 => "此记录编号含有成人，请将成人与儿童拆开导入，请将成人编码输入到儿童编码里",
				300181 => "未将成人编码输入到儿童编码里",
				300182 => "儿童订购的舱位只能是Y舱、C舱、F舱，请检查您的PNR记录编号",
				300183 => "此记录编号为“TN”状态不是有效记录编号，请检查您的PNR记录编号",
				300184 => "很抱歉，此记录编号为联程票，平台暂不支持联程票",
				300185 => "鹰联(EU)航空儿童票，只能是O舱，其它舱位无效",
				300186 => "当前暂不支持往返儿童票，请将往返儿童票拆成两个单程编码导入",
				300187 => "东航X舱价格有变动，如要出票，请致电我们",
				300188 => "此记录编号为“HN”状态不是有效记录编号，请检查您的PNR记录编号",
				300189 => "此记录编号为“HX”状态不是有效记录编号，请检查您的PNR记录编号",
				300190 => "南航(CZ)儿童需要加SSR项",
				300191 => "南航(CZ)儿童票姓名后面不用输入儿童标识 CHD",
				300192 => "南航(CZ)儿童票姓名后面请输入儿童标识 CHD",
				300193 => "东航X舱不适用于外籍乘客，如有疑问请联系我们客服",
				300194 => "您复制的黑屏数据有问题，请勿修改且保持原有的黑屏数据，如有问题请及时联系我们",
				300195 => "请备注OSI项",
				300197 => "您订的往返程编码不属于同一家航空公司，请检查后重新导入",
				300198 => "REMARK OFFICE（需要授权）",
				300199 => "未知信息，请联系技术人员",
				300200 => "票面价格不相符",
				300201 => "证件编号相同",
				300202 => "邮政编码为空",
				300203 => "采购商对应的订单不不在",
				300204 => "供应商ID与订单对应的供应商ID不匹配",
				300205 => "采购商账户与订单对应的采购商账户不匹配",
				300206 => "订单状态不允许升舱",
				300207 => "订单状态不能取消订单",
				300208 => "订单不存在",
				300209 => "订单状态不允许退废票",
				300210 => "订单状态不允许改签",
				300211 => "升舱的乘客姓名在订单乘客中不存在",
				300212 => "升舱舱位有误",
				300213 => "身份证件号格式有误！(开头必须是NI)",
				300214 => "获取行程单信息失败，请检查行程单编号或采购商用户名是否正确",
				300215 => "升舱时间小于当前时间",
				300216 => "出发时间小于当前时间",
				300217 => "暂不能类型为空",
				300218 => "暂不能类型必须为(A,B,C)",
				300219 => "退，废票标识不合法，必须为(A,B)",
				300220 => "退，废票标识与乘客人数不相等",
				300221 => "退废票标识与票号不相等",
				300222 => "该订单状态不属于暂不能出票",
				300223 => "该订单状态不属于暂不能废票",
				300224 => "该订单状态不属于暂不能退票",
				300225 => "更新暂不能订单失败",
				300226 => "该订单没有退/废票信息",
				300227 => "没有订单改签信息",
				300228 => "升舱的PNR编码与订单的PNR编码不相同",
				300229 => "该供应商没有对应的officeNum",
				300230 => "政策没有对应的OfficeNum",
				300231 => "退/废票姓名不存在订单的姓名中",
				300232 => "请填写退/废票原因",
				300233 => "邮政编码必须为数字",
				300234 => "电话号码格式必须为数字",
				300235 => "PNR编码必须为6位",
				300236 => "PNR编码与PNRInfo中的Pnr编码不相等或是大编码不为6位",
				300237 => "PnrInfo中PNR编码格与大编码格式有误",
				300238 => "退废票备注必须为A，B，C，D",
				300239 => "出发日期小于当前日期",
				300240 => "该供应商不能出VIP账户",
				300241 => "该供应商必须传证件号",
				300242 => "系统商授权记录未审核",
				300243 => "系统商授权记录未通过审核",
				300244 => "系统商未获得授权",
				300245 => "未检测到此系统商账号",
				300246 => "采购商不能创建南航S舱的订单",
				300247 => "乘客姓名长度有误(中文不能超过11个字符，英文不能超过24个字符)",
				300248 => "退/废票备注不能超过500个字符",
				300249 => "乘客姓名中包含航信系统无法识别的生僻字，请使用拼音代替",
				300250 => "没有获取到特价舱位价格",
				300251 => "初始化经销商信息失败",
				300252 => "政策ID为空",
				300253 => "政策ID未填写",
				300254 => "采购商不具有查询航班权限",
				300255 => "当前时间不在供应商上班时间内，无法创单",
				300256 => "PNR不能为空",
				300257 => "深圳出发无法下单",
				300258 => "请转到升舱接口",
				300259 => "请转到获取升舱信息接口",
				300260 => "获取儿童PNR内容异常",
				300261 => "获取儿童价格异常",
				300262 => "是否取消平台PNR只能取值'Y'或'N'",
				300263 => "退/废票票号不存在订单的票号中",
				300264 => "未获取到供应商上下班时间",
				300265 => "校验支付金额不一致",
				300266 => "乘客证件号错误",
				300285 => "票号状态是:USED/FLOWN LIFT/BOARDED CHECKED IN,不能退废",
				300280 => "实时创单订位失败,黑屏返回NN/NH时,如果查询该航班Y舱无位,但B舱有位,返回该错误码",
				300300 => "该舱位无运价，请重新选择舱位",
				500001 => "该采购商ID与订单编号对应的订单不存在",
				500002 => "订单不属于采购商的订单",
				500003 => "初始化分润金额有误",
				500004 => "该订单对应的采购商和经销商账户没有代扣账户",
				500005 => "存入支付宝状态失败",
				500006 => "更新订单支付宝状态失败",
				500007 => "该订单已经支付",
				500008 => "支付宝自动支付失败",
				500009 => "更新订单支付方式失败",
				500010 => "更新行程单状态失败",
				500011 => "支付类型未填写",
				500012 => "支付类型为空",
				500013 => "支付类型必须为ZFB",
				500014 => "该升舱编号已经支付",
				500015 => "升舱编号为空",
				500016 => "升舱编号未填写",
				500017 => "该升舱编号不属于该采购商",
				500018 => "该行程单编号已经支付成功",
				500019 => "行程单编号为空",
				500020 => "行程单编号未填写",
				500021 => "采购商对应的行程单编号不存在",
				500022 => "该行程单编号不存在",
				500023 => "支付宝自动代扣异常",
				500024 => "支付成功，更新订单失败",
				500025 => "支付成功，但该订单编号不存在",
				500026 => "自动支付失败",
				510027 => "支付类型必须为directPay或BankPay",
				510028 => "请填写银行缩写",
				500029 => "该订单的状态不为等待支付",
				500030 => "订单超过支付时限",
				500031 => "分润错误，无法支付！",
				600001 => "供应商账户未填写",
				600002 => "供应商账户为空",
				600003 => "订单编号未填写",
				600004 => "订单编号为空",
				600005 => "解析xml异常",
				600006 => "生成响应xml异常",
				600007 => "未查询到此订单详细数据",
				600008 => "供应商账户不存在",
				660000 => "未知异常",
				660009 => "订单解锁失败",
				660010 => "此订单已经被解锁",
				660011 => "订单锁定反序列化异常",
				660012 => "锁单的平台账号未填写",
				660013 => "锁单的平台账号为空",
				660014 => "此订单已经被锁单",
				660015 => "订单锁定失败",
				660016 => "订单锁定序列化异常",
				660017 => "锁单的平台账号必须是数字",
		);
		return $ar[$code];
	}
}

/**
 * 验证身份证号
 * @param $vStr
 * @return bool
 */
if(!function_exists('isCreditNo')){
	function isCreditNo($vStr)
	{
		$vCity = array(
			'11','12','13','14','15','21','22',
			'23','31','32','33','34','35','36',
			'37','41','42','43','44','45','46',
			'50','51','52','53','54','61','62',
			'63','64','65','71','81','82','91'
		);

		if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;

		if (!in_array(substr($vStr, 0, 2), $vCity)) return false;

		$vStr = preg_replace('/[xX]$/i', 'a', $vStr);
		$vLength = strlen($vStr);

		if ($vLength == 18)
		{
			$vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
		} else {
			$vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
		}

		if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
		if ($vLength == 18)
		{
			$vSum = 0;

			for ($i = 17 ; $i >= 0 ; $i--)
			{
				$vSubStr = substr($vStr, 17 - $i, 1);
				$vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr , 11));
			}

			if($vSum % 11 != 1) return false;
		}

		return true;
	}
}


if(!function_exists('logger'))
{
	function logger($string)
	{
		write_file(APPPATH.'wxlog.log', $string.date('Y-m-d H:i:s')."\n",'ab+');
	}
}

if (!function_exists('fomate_range_date'))
{
	function fomate_range_date($start = '', $end = '')
	{
		$re = array();
		$s = strtotime($start);
		$e = strtotime($end)- (60 * 60 * 24);
		$i = 0;
		do
		{
			$re[$i] = date('Y-m-d', $s);
			$s += 60 * 60 * 24;
			$i++;
		}
		while ($s <= $e);

		return $re;
	}
}



if ( ! function_exists('format_table_field'))
{
	/**
	 * 格式化sql语句 字段
	 * @param array $fields  array('id','name as nick')
	 * @param string $table   表名
	 */

	function format_table_field($fields = array(),$table = '')
	{
		$str = '';
		if(!empty($fields))
		{
			if(!empty($table))
			{
				foreach ($fields as $key=>$item)
				{
					if ($key) {
						$str .= ',' . $table . '.' . $item;

					} else {
						$str .= $table . '.' . $item;
					}
				}
			}
			if(empty($table))
			{
				$str = implode(',', $fields);
			}
		}
		return $str ;
	}
}


if (!function_exists('fdate'))
{
	function fdate($date)
	{
		$unixtime = strtotime($date);
		return date('m-d', $unixtime);

	}
}


if (!function_exists('fdatetime'))
{
	function fdatetime($date)
	{
		$unixtime = strtotime($date);
		return date('m-d H:i:s', $unixtime);

	}
}

if (!function_exists('fdate'))
{
	function fdate($date)
	{
		$unixtime = strtotime($date);
		return date('m-d', $unixtime);

	}
}

if (!function_exists('ftime'))
{
	function ftime($date)
	{
		$unixtime = strtotime($date);
		return date('H:i:s', $unixtime);

	}
}